package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewActivity extends AppCompatActivity {

    private ListView listView;
    private String data[]=new String[]{"Apple","Banana","Orange","Watermelon","Pear",
    "Grape","PineApple","strawberry","Cherry","Mango","Apple","Banana","Orange","Watermelon","Pear",
            "Grape","PineApple","strawberry","Cherry","Mango"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        listView =(ListView)findViewById(R.id.list_view);//找到对应的组件

        //ListView和Adapter搭配一起使用
        //ArrayAdapter数组适配器的使用
        //保存有列表项内容的数组
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,data);

        //listview和适配器要组合在一起才能发挥作用
        listView.setAdapter(adapter);



    }
}